/**  
 * Copyright (c) 2010 University of Pennsylvania.
 *     All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an "AS
 *  IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 *  express or implied.  See the License for the specific language
 *  governing permissions and limitations under the License.
 *
 */
 
void init_mlogs();

#ifdef USE_MEMFILES
int8_t *file_buffer;
int16_t filebuffer_pos, filebuffer_size, filebuffer_alloc;
typedef struct { 
} FILE;

void init_filebuffer(int file_size);
void reset_filebuffer();
#endif

#if defined(TOSSIM) || defined(USE_MEMFILES) 
void dolog_routestats(FILE *f);
void dostore_link(FILE *f);
void dostore_trees(FILE *f);
void dostore_joinstate(FILE *f);

void store_joinstate();
void load_joinstate();
void route_request(ROUTE_MSG *msg);
void finish_route(ROUTE_MSG *msg);
void route_logunreachable(ROUTE_MSG *msg);
void forward_request(FORWARD_MSG *msg);
void finish_forward(FORWARD_MSG *msg);
void forward_logunreachable(FORWARD_MSG *msg);
void join_logpair(uint8_t query_id, ADDRESS source1, ADDRESS source2);
void join_lognode(uint8_t query_id, ADDRESS join_node, ADDRESS other_source);
void join_logcoordcost(uint8_t query_id, ADDRESS coord_id, COORD_COST cost);
void join_logcoorddecision(uint8_t query_id, ADDRESS coord_id, COORD_DECISION decision);
void join_logselest(uint8_t query_id, ADDRESS src_node, ADDRESS target_node, uint8_t src_sel,
  uint8_t target_sel, uint8_t join_sel);
void store_state();
void log_routestats();
void load_state();
void load_values();
void store_trees();
void load_trees();
void log_sendmsg(ADDRESS addr, uint8_t *msg, uint8_t len);
void log_rcvmsg(ADDRESS addr, uint8_t *msg, uint8_t len);
void log_sendcmd(uint8_t node_count, ADDRESS *nodes, uint8_t *cmd, uint8_t len);
void log_sendcmdconf(uint8_t node_count, ADDRESS *nodes, uint8_t *cmd, uint8_t len, uint8_t success);
void log_rcvcmd(ADDRESS addr, uint8_t *cmd, uint8_t len);
void log_dropcmd(uint8_t node_count, ADDRESS *nodes, uint8_t *cmd, uint8_t len, uint8_t code);
void log_sendcmdhi(uint8_t *cmd, uint8_t len);
void log_rcvcmdhi(uint8_t *cmd, uint8_t len);
void log_querysample(uint8_t attr, ATTRIBUTE v);
void log_queryjoinin(ADDRESS source_node, uint8_t tuple_len, ATTRIBUTE *tuple);
void log_queryjoinout(ADDRESS dest_node, uint8_t tuple_len, ATTRIBUTE *tuple);
void log_querycostmodel(ADDRESS source_node, ADDRESS target_node, ADDRESS join_node, uint16_t cost);
void log_multicastrequest(uint8_t node_count, ADDRESS *nodes, uint8_t multicastbuffer_len,
  uint8_t *multicast_buffer);
void log_multicastcompleted(ADDRESS source_node);
void log_repairforward(uint8_t success, ADDRESS source_node, ADDRESS dest_node,
  ADDRESS old_neighbornode, ADDRESS new_neighbornode, int8_t len_diff, ADDRESS *old_path,
  uint8_t old_pathlen, ADDRESS *new_path, uint8_t new_pathlen);
#endif
